/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.cheln.explorer.ds.util;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import cn.cheln.explorer.beans.FileUtil;
import cn.cheln.explorer.config.Constants;
import cn.cheln.explorer.ds.MediaArgs;
import cn.cheln.support.log.Logs;
import cn.cheln.support.unknown.ComparatorRepo;


/**
 *
 * @author Administrator
 */
public class FileMgrCategory {
    public static List<String> mediaCategory = Arrays.asList(new String[]{
        "audio","video","image"
    });
    public static Map<String, String> categoryMap = new TreeMap<String, String>(ComparatorRepo.stringKey);

    static {
        categoryMap.put(MediaArgs.APK_MIME, Constants.CateContants.CATE_PACKAGE);
        categoryMap.put("image", Constants.CateContants.CATE_IMAGES);
        categoryMap.put("audio", Constants.CateContants.CATE_MUSIC);
        categoryMap.put("video", Constants.CateContants.CATE_VIDEO);
        categoryMap.put("application", Constants.CateContants.CATE_DOCS);
        categoryMap.put("text", Constants.CateContants.CATE_DOCS);
        categoryMap.put("lewa/theme", Constants.CateContants.CATE_THEME);
    }

    public static Map<String, String> getCategoryMap() {
        return categoryMap;
    }

    public static String getCategory(String mime) {
        if(mime==null){
            return null;
        }
        if (categoryMap.containsKey(mime)) {
            return categoryMap.get(mime);
        } else {
            String variable = FileUtil.parseMimePrefix(mime);
            if ((variable = categoryMap.get(variable)) == null) {
                Logs.i(""+mime);
            	throw new IllegalStateException("cannt find any category mapped the mime");
            }
            return variable;
        }
    }
}
